package com.yn.admin.zy;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yn.common.model.zy.TCarFleetManageDO;
import com.yn.common.page.BasePage;
import com.yn.common.request.sc.CarFleetManageRequest;
import com.yn.common.request.sc.CarManageRequest;
import com.yn.common.request.sc.PageParamRequest;
import com.yn.common.response.driver.FleetManageDetailResponse;
import com.yn.common.response.driver.ZyDriverOrderListResponse;
import com.yn.common.response.sc.BaseResult;
import com.yn.service.zy.TCarFleetManageService;
import com.yn.service.zy.model.dto.TCarFleetManageDTO;
import com.yn.service.zy.model.query.TCarFleetManageQuery;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.List;

@RestController
@RequestMapping("/tcarfleetmanage")
@Api(tags = "车队相关接口")
public class TCarFleetManageController {
    @Autowired
    private TCarFleetManageService tCarFleetManageService;

    /**
     * 分页获取车队列表
     * @param query
     * @param basePage
     * @return
     */
/*    @ApiOperation("分页获取车队列表")
    @GetMapping("/list-page")
    public BaseResult<IPage<TCarFleetManageDTO>> listPage(TCarFleetManageQuery query, PageParamRequest basePage){
        IPage<TCarFleetManageDO> tCarFleetManageDTOIPage = tCarFleetManageService.listPage(query,basePage);
        IPage<TCarFleetManageDTO> convert = tCarFleetManageDTOIPage.convert(TCarFleetManageDTO::transform);
        return BaseResult.success(convert);
    }*/

    /**
     * 分页获取车队列表
     * @param query
     * @param basePage
     * @return
     */
    @ApiOperation("分页获取车队列表")
    @GetMapping("/list-page")
    public BaseResult<BasePage<TCarFleetManageDTO>> listPage1(TCarFleetManageQuery query, PageParamRequest basePage){
        BasePage<TCarFleetManageDTO> convert = tCarFleetManageService.listPage1(query,basePage);

        return BaseResult.success(convert);
    }
    /**
     * 根据id查询车队信息——用于编辑回显
     * */
    @ApiOperation("根据id查询车队信息")
    @GetMapping("/info")
    public BaseResult<FleetManageDetailResponse> getInfo(@ApiParam("车队id") @RequestParam @NotNull Integer id) {
        return BaseResult.success(tCarFleetManageService.getFleetDetailInfo(id));
    }

    /**
     * 获取车队详情——包括部分车辆信息
     * @param id
     * @return
     */
  /*  @ApiOperation("获取车队详情")
    @GetMapping("/detail/info")
    public BaseResult<TCarFleetManageDTO> info(@RequestParam(value = "id",required = true)
                           @NotNull(message = "请选择")
                           @ApiParam(value = "主键id",required = true) Integer id){
        return BaseResult.success(tCarFleetManageService.selectById(id));
    }*/

    /**
     * 批量审核
     * @param cardFleetIds
     * @param auditStatus
     * @return
     */
    @PostMapping("/batch-audit")
    @ApiOperation("批量审核")
    public BaseResult batchAudit(@RequestBody List<Integer> cardFleetIds,
                                 @RequestParam(value = "auditStatus",required = true)
                                 @ApiParam(value = "审核状态 1同意 3不同意",required = true)
                                 @NotNull(message = "请选择审核状态") Integer auditStatus){
        tCarFleetManageService.batchAudit(cardFleetIds,auditStatus);
        return BaseResult.success();
    }
    /**
     * 添加车队
     * @param request
     */
    @PostMapping("/save")
    @ApiOperation(value = "添加车队")
    public BaseResult<String> save(@RequestBody @Validated CarFleetManageRequest request){
        tCarFleetManageService.saveFleet(request);
        return BaseResult.success();
    }

    /**
     * 为某个车队添加车辆信息
     *传过来的id时车队id
     * */
    @PostMapping("/save/car")
    @ApiOperation(value = "为车队添加车辆信息——丢弃")
    public BaseResult<String> saveCar(@RequestBody @Validated CarManageRequest request,
                                      @RequestParam(value = "id",required = true)
                                      Integer id){
        tCarFleetManageService.saveCar(request,id);
        return BaseResult.success();
    }
}
